package middleware

import (
	"mcode/pkg/query"
	"strconv"

	"github.com/gin-gonic/gin"
)

// Pagination 分页中间件
func Pagination() gin.HandlerFunc {
	return func(c *gin.Context) {
		page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
		pageSize, _ := strconv.Atoi(c.DefaultQuery("size", "10"))

		req := query.NewPagination(page, pageSize)

		c.Set("pagination", req)
		c.Next()
	}
}
